package vn.com.servicedirectory.controller;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import vn.com.servicedirectory.common.CommonVariable;
import vn.com.servicedirectory.forms.GeographyIndexForm;
import vn.com.servicedirectory.model.GovernmentOffice;
import vn.com.servicedirectory.service.GovOfficeRegionService;

@Controller
public class GeographyController {
	
	@Inject
	protected GovOfficeRegionService govOfficeService;
	public GeographyController() {
	}
	@RequestMapping(value = CommonVariable.PAGE_GEOGRAPHY_INDEX_HTML, method = RequestMethod.GET)
	public String showIndex(Model model,HttpServletRequest request) {
		GeographyIndexForm geographyIndexForm =new GeographyIndexForm();
		geographyIndexForm.setFormTitle(CommonVariable.FORM_DEMO_TITLE);
		
		model.addAttribute("geographyIndex", govOfficeService.findByName("all", 0, 5, true));
		return CommonVariable.PAGE_GEOGRAPHY_INDEX;
	}

	@RequestMapping(value=CommonVariable.PAGE_GEOGRAPHY_DETAILS_HTML,method= RequestMethod.GET)
	public String viewDetails(Model model, HttpServletRequest request){
		GovernmentOffice obj=govOfficeService.findById(Integer.parseInt(request.getParameter("id")));
		model.addAttribute("govDetails", obj);
		return  CommonVariable.PAGE_GEOGRAPHY_DETAILS;
	}
	@RequestMapping(value = "geographyDetailsBack")
	public String back() {
		return "redirect:"+CommonVariable.PAGE_GEOGRAPHY_INDEX_HTML;
	}

}
